﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QueryData;

public class 显式加载数据
{
    void MyMethod()
    {
        using (var db = new BasicDbContext())
        {
            var mainEntity = db.MainEntities.First();
            db.Entry(mainEntity)
                .Collection(m => m.SubEntities)
                .Load();

            db.Entry(mainEntity).Collection(m => m.SubEntities)
                .Query()
                .Where(x => x.Time < DateTimeOffset.Now)
                .Count();

            var subEntity = db.SubEntities.First();
            db.Entry(subEntity).Reference(s => s.MainEntity).Load();


        }
    }
}
